package com.pfizer.Utils;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pfizer.pfizerExpertForPad.R;
/**
 * NoticeBoardListAdapter--<b>公佈欄信息的數據適配器，用於綁定listview</b>--
 * 
 * @see android.widget.BaseAdapter
 * @author krui
 * @version 1.0 2011/11/24
 */
public class NoticeBoardListAdapter extends BaseAdapter {
	
	List<Map<String, Object>> list;
	Context mContext;
	private int selectItem = 0; // 定義初始選定位置
	public NoticeBoardListAdapter() {
		// TODO Auto-generated constructor stub
	}
/**
 * 構造函數用於接受數據源與上下文對象
 * @param list（數據源）
 * @param mContext（上下文對象）
 */
	public NoticeBoardListAdapter(List<Map<String, Object>> list,
			Context mContext) {
		this.list = list;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		NoticeBoardViewHolder vh = null;
		if (convertView == null) {
			vh = new NoticeBoardViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.noticeboardlistitem, null);
			vh.tvBgTime = (TextView)convertView.findViewById(R.id.tvBgTime);
			vh.tvTitle = (TextView)convertView.findViewById(R.id.tvTitle);
			vh.tvPublisher = (TextView)convertView.findViewById(R.id.tvPublisher);
			vh.ivShowDetail=(ImageView)convertView.findViewById(R.id.ivShowDetail);
			convertView.setTag(vh);
		}else {
			vh = (NoticeBoardViewHolder) convertView.getTag();
		}
		
		//写数据
		vh.tvBgTime.setText((String)list.get(position).get("BgTime"));
		vh.tvTitle.setText((String)list.get(position).get("Title"));
		vh.tvPublisher.setText("發佈者："+(String)list.get(position).get("Publisher"));
		// 更换Item背景
		if(position % 2 ==0)
		{
			convertView.setBackgroundResource(R.drawable.nibg01);
		}
		else
		{
			convertView.setBackgroundResource(R.drawable.nibg02);
		}
		if (position == selectItem) {
			vh.ivShowDetail.setVisibility(View.VISIBLE);
		} else {
			vh.ivShowDetail.setVisibility(View.INVISIBLE);
		}
		
		return convertView;
	}
	public void setSelectItem(int selectItem) {
		this.selectItem = selectItem;
	}
}
